home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 July: Mac OS SDK / Dev.CD Jul 96 SDK / Dev.CD Jul 96 SDK1.toast / Development Kits (Disc 1) / OpenDoc Development Framework / Developer University / DUProjects / Sample4 / Sources / Frame.cpp < prev    next >
Encoding:
Text File  |  1996-04-08  |  3.8 KB  |  135 lines  |  [TEXT/CWIE]

  1. //    Copyright © 1995-96 Apple Computer, Inc. All rights reserved.
  2. //    Release Version:    $ ODF 1 $
  3.  
  4. //=======================================================================
  5. #ifndef FRAME_H
  6. #include "Frame.h"
  7. #endif
  8.  
  9. #ifndef PART_H
  10. #include "Part.h"
  11. #endif
  12.  
  13. // ----- Framework Layer -----
  14. #ifndef FWUTIL_H
  15. #include "FWUtil.h"                // FW_CFacetContext, FW_Beep()
  16. #endif
  17.  
  18. #ifndef FWCONTXT_H
  19. #include "FWContxt.h"            // FW_CViewContext
  20. #endif
  21.  
  22. // ----- Graphic Includes -----
  23. #ifndef FWRECT_H
  24. #include <FWRect.h>                // FW_CRect
  25. #endif
  26.  
  27. #ifndef FWRECSHP_H
  28. #include "FWRecShp.h"            // FW_CRectShape
  29. #endif
  30.  
  31. #ifndef FWPICSHP_H
  32. #include "FWPicShp.h"            // FW_PPicture, FW_CPictureShape
  33. #endif
  34.  
  35. #ifndef FWRRCSHP_H
  36. #include "FWRRcShp.h"            // FW_CRoundRectShape
  37. #endif
  38.  
  39. #ifndef SOM_DevUniv_STalker_xh
  40. #include "STalker.xh"            // for STalker
  41. #endif 
  42.  
  43. //========================================================================================
  44. #ifdef FW_BUILD_MAC
  45. #pragma segment Sample4
  46. #endif
  47.  
  48. //========================================================================================
  49. FW_DEFINE_AUTO(CSample4Frame)
  50.  
  51. const FW_Boolean kWaitUntilDone = TRUE;    // don't return until talking is finished.
  52. //========================================================================================
  53. CSample4Frame::CSample4Frame(Environment* ev, ODFrame* odFrame, 
  54.                                     FW_CPresentation* presentation, CSample4Part* sample3Part)
  55.   : FW_CFrame(ev, odFrame, presentation, sample3Part),
  56.       fSOMTalker(NULL),
  57.       fPictShape(NULL)
  58. {
  59.     this->MyInitPicture(ev);
  60. #ifdef FW_BUILD_MAC                    // can we do text-to-speech on Windows?
  61.     fSOMTalker = new DevUniv_STalker;    
  62.     fSOMTalker->SayString(ev, "I use ODF", !kWaitUntilDone);    // say it!
  63. #endif
  64.     FW_END_CONSTRUCTOR
  65. }
  66.  
  67. //----------------------------------------------------------------------------------------
  68. void
  69. CSample4Frame::MyInitPicture(Environment* ev)
  70. {
  71.     FW_CSharedLibraryResourceFile resFile(ev);        // PICT resource in shared library
  72. #ifdef FW_BUILD_MAC
  73.     const short kPictID = 2000;
  74.     FW_CPicture picture(resFile, kPictID);
  75.     fFrameRect = this->GetBounds(ev);                // Get new Frame Rect
  76.     fPictShape = FW_NEW(FW_CPictureShape, (picture, fFrameRect));
  77. #endif
  78. }
  79.  
  80. //----------------------------------------------------------------------------------------
  81. CSample4Frame::~CSample4Frame()
  82. {
  83.     FW_START_DESTRUCTOR
  84.     delete fPictShape;
  85. #ifdef FW_BUILD_MAC
  86.     delete fSOMTalker;
  87. #endif
  88. }
  89.  
  90. //----------------------------------------------------------------------------------------
  91. void 
  92. CSample4Frame::Draw(Environment *ev, ODFacet* odFacet, ODShape* invalidShape)    // Override
  93. {
  94.     FW_CViewContext context(ev, this, odFacet, invalidShape);
  95.     // erase invalid shape
  96.     FW_CRect invalidRect;
  97.     context.GetClipRect(invalidRect);
  98.     FW_CRectShape::RenderRect(context, invalidRect, FW_kFill, FW_kWhiteEraseInk);
  99.  
  100.     // draw the picture
  101.     fPictShape->Render(context);
  102.  
  103.     // draw a frame around it
  104.     FW_CRoundRectShape::RenderRoundRect(context,
  105.                                         fFrameRect, 
  106.                                         FW_CPoint(FW_IntToFixed(30), FW_IntToFixed(30)),
  107.                                         FW_kFrame,
  108.                                         FW_CInk(FW_kRGBBlue));
  109. }
  110.  
  111. //----------------------------------------------------------------------------------------
  112. FW_Boolean 
  113. CSample4Frame::DoMouseDown(Environment* ev, const FW_CMouseEvent& theMouseEvent)
  114. {    
  115.     FW_UNUSED(ev);
  116.     FW_UNUSED(theMouseEvent);
  117. #ifdef FW_BUILD_MAC
  118.     fSOMTalker->SayString(ev, "Oh Boy", !kWaitUntilDone);    // say it!
  119. #endif
  120.     return TRUE;    // we handled event
  121. }
  122.  
  123. //----------------------------------------------------------------------------------------
  124. void 
  125. CSample4Frame::FrameShapeChanged(Environment* ev)
  126. {
  127.     FW_CFrame::FrameShapeChanged(ev);
  128.     fFrameRect = this->GetBounds(ev);        // Get new frame rect
  129.     // modify picture
  130.     FW_CPicture picture = fPictShape->GetPicture();
  131.     fPictShape->SetGeometry(picture, fFrameRect);
  132.     // force redraw of whole frame
  133.     this->Invalidate(ev, fFrameRect);            
  134. }
  135.